import request from '@/utils/request'

// 查询优惠券列表
export function listCoupon(query) {
  return request({
    url: '/merchant/coupon/list',
    method: 'get',
    params: query
  })
}

// 查询优惠券详细
export function getCoupon(id) {
  return request({
    url: '/merchant/coupon/' + id,
    method: 'get'
  })
}

// 新增优惠券
export function addCoupon(data) {
  return request({
    url: '/merchant/coupon',
    method: 'post',
    data: data
  })
}

// 修改优惠券
export function updateCoupon(data) {
  return request({
    url: '/merchant/coupon',
    method: 'put',
    data: data
  })
}

// 删除优惠券
export function delCoupon(id) {
  return request({
    url: '/merchant/coupon/' + id,
    method: 'delete'
  })
}

// 导出优惠券
export function exportCoupon(query) {
  return request({
    url: '/merchant/coupon/export',
    method: 'get',
    params: query
  })
}
// 下架优惠券
export function offlineCoupon(ids) {
  var url =  '/merchant/coupon/offline?';

  if (ids instanceof Array) {
    for(var i = 0 ; i <ids.length;i++ ){
      var id = ids[i];
      url = url+ "ids="+id + "&";
    }
  }else{
    url = url+ "ids="+ids;
  }
  return request({
    url: url,
    method: 'get',
  })

}
